using System;
using System.Drawing;
using System.Collections;
using System.ComponentModel;
using System.Windows.Forms;

namespace CaptureTest
{
	/// <summary>
	/// Summary description for CompressionProps.
	/// </summary>
	public class CompressionProps : System.Windows.Forms.Form
	{
        private System.Windows.Forms.Button btnOk;
        private System.Windows.Forms.Button btnCancel;
        private System.Windows.Forms.Label label1;
        public System.Windows.Forms.TextBox txtKeyFrame;
        public System.Windows.Forms.TextBox txtPFrames;
        public System.Windows.Forms.TextBox txtWindowSize;
        public System.Windows.Forms.TextBox txtQuality;
        public System.Windows.Forms.TrackBar trkQuality;
        public System.Windows.Forms.Label labKeyFrame;
        public System.Windows.Forms.Label labPFrames;
        public System.Windows.Forms.Label labWindowSize;
        public System.Windows.Forms.Label labQuality;
        public System.Windows.Forms.CheckBox chkKeyFrame;
        public System.Windows.Forms.CheckBox chkPFrames;
        public System.Windows.Forms.CheckBox chkWindowSize;
        public System.Windows.Forms.CheckBox chkQuality;
		/// <summary>
		/// Required designer variable.
		/// </summary>
		private System.ComponentModel.Container components = null;

		public CompressionProps()
		{
			//
			// Required for Windows Form Designer support
			//
			InitializeComponent();

			//
			// TODO: Add any constructor code after InitializeComponent call
			//
		}

		/// <summary>
		/// Clean up any resources being used.
		/// </summary>
		protected override void Dispose( bool disposing )
		{
			if( disposing )
			{
				if(components != null)
				{
					components.Dispose();
				}
			}
			base.Dispose( disposing );
		}

		#region Windows Form Designer generated code
		/// <summary>
		/// Required method for Designer support - do not modify
		/// the contents of this method with the code editor.
		/// </summary>
		private void InitializeComponent()
		{
            this.txtKeyFrame = new System.Windows.Forms.TextBox();
            this.txtPFrames = new System.Windows.Forms.TextBox();
            this.txtWindowSize = new System.Windows.Forms.TextBox();
            this.labKeyFrame = new System.Windows.Forms.Label();
            this.labPFrames = new System.Windows.Forms.Label();
            this.labWindowSize = new System.Windows.Forms.Label();
            this.trkQuality = new System.Windows.Forms.TrackBar();
            this.txtQuality = new System.Windows.Forms.TextBox();
            this.labQuality = new System.Windows.Forms.Label();
            this.btnOk = new System.Windows.Forms.Button();
            this.btnCancel = new System.Windows.Forms.Button();
            this.label1 = new System.Windows.Forms.Label();
            this.chkKeyFrame = new System.Windows.Forms.CheckBox();
            this.chkPFrames = new System.Windows.Forms.CheckBox();
            this.chkWindowSize = new System.Windows.Forms.CheckBox();
            this.chkQuality = new System.Windows.Forms.CheckBox();
            ((System.ComponentModel.ISupportInitialize)(this.trkQuality)).BeginInit();
            this.SuspendLayout();
            // 
            // txtKeyFrame
            // 
            this.txtKeyFrame.Location = new System.Drawing.Point(192, 48);
            this.txtKeyFrame.Name = "txtKeyFrame";
            this.txtKeyFrame.Size = new System.Drawing.Size(32, 20);
            this.txtKeyFrame.TabIndex = 0;
            this.txtKeyFrame.Text = "";
            this.txtKeyFrame.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtKeyFrame.Validating += new System.ComponentModel.CancelEventHandler(this.txtKeyFrame_Validating);
            // 
            // txtPFrames
            // 
            this.txtPFrames.Location = new System.Drawing.Point(192, 80);
            this.txtPFrames.Name = "txtPFrames";
            this.txtPFrames.Size = new System.Drawing.Size(32, 20);
            this.txtPFrames.TabIndex = 1;
            this.txtPFrames.Text = "";
            this.txtPFrames.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtPFrames.Validating += new System.ComponentModel.CancelEventHandler(this.txtPFrames_Validating);
            // 
            // txtWindowSize
            // 
            this.txtWindowSize.Location = new System.Drawing.Point(192, 112);
            this.txtWindowSize.Name = "txtWindowSize";
            this.txtWindowSize.Size = new System.Drawing.Size(32, 20);
            this.txtWindowSize.TabIndex = 2;
            this.txtWindowSize.Text = "";
            this.txtWindowSize.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtWindowSize.Validating += new System.ComponentModel.CancelEventHandler(this.txtWindow_Validating);
            // 
            // labKeyFrame
            // 
            this.labKeyFrame.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.labKeyFrame.Location = new System.Drawing.Point(32, 48);
            this.labKeyFrame.Name = "labKeyFrame";
            this.labKeyFrame.Size = new System.Drawing.Size(112, 24);
            this.labKeyFrame.TabIndex = 3;
            this.labKeyFrame.Text = "KeyFrame every";
            // 
            // labPFrames
            // 
            this.labPFrames.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.labPFrames.Location = new System.Drawing.Point(32, 80);
            this.labPFrames.Name = "labPFrames";
            this.labPFrames.Size = new System.Drawing.Size(160, 23);
            this.labPFrames.TabIndex = 4;
            this.labPFrames.Text = "PFrames Per KeyFrame";
            // 
            // labWindowSize
            // 
            this.labWindowSize.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.labWindowSize.Location = new System.Drawing.Point(32, 112);
            this.labWindowSize.Name = "labWindowSize";
            this.labWindowSize.TabIndex = 5;
            this.labWindowSize.Text = "WindowSize";
            // 
            // trkQuality
            // 
            this.trkQuality.Location = new System.Drawing.Point(8, 160);
            this.trkQuality.Maximum = 100;
            this.trkQuality.Name = "trkQuality";
            this.trkQuality.Size = new System.Drawing.Size(192, 50);
            this.trkQuality.TabIndex = 9;
            this.trkQuality.TickFrequency = 5;
            this.trkQuality.ValueChanged += new System.EventHandler(this.Quality_Value_Changed);
            // 
            // txtQuality
            // 
            this.txtQuality.Location = new System.Drawing.Point(200, 176);
            this.txtQuality.Name = "txtQuality";
            this.txtQuality.Size = new System.Drawing.Size(32, 20);
            this.txtQuality.TabIndex = 10;
            this.txtQuality.Text = "";
            this.txtQuality.TextAlign = System.Windows.Forms.HorizontalAlignment.Right;
            this.txtQuality.Validating += new System.ComponentModel.CancelEventHandler(this.txtQuality_Validating);
            // 
            // labQuality
            // 
            this.labQuality.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.labQuality.Location = new System.Drawing.Point(8, 144);
            this.labQuality.Name = "labQuality";
            this.labQuality.Size = new System.Drawing.Size(152, 16);
            this.labQuality.TabIndex = 11;
            this.labQuality.Text = "Quality";
            // 
            // btnOk
            // 
            this.btnOk.DialogResult = System.Windows.Forms.DialogResult.OK;
            this.btnOk.Location = new System.Drawing.Point(48, 232);
            this.btnOk.Name = "btnOk";
            this.btnOk.Size = new System.Drawing.Size(75, 32);
            this.btnOk.TabIndex = 12;
            this.btnOk.Text = "Ok";
            // 
            // btnCancel
            // 
            this.btnCancel.CausesValidation = false;
            this.btnCancel.DialogResult = System.Windows.Forms.DialogResult.Cancel;
            this.btnCancel.Location = new System.Drawing.Point(152, 232);
            this.btnCancel.Name = "btnCancel";
            this.btnCancel.Size = new System.Drawing.Size(75, 32);
            this.btnCancel.TabIndex = 13;
            this.btnCancel.Text = "Cancel";
            // 
            // label1
            // 
            this.label1.Font = new System.Drawing.Font("Microsoft Sans Serif", 10F, System.Drawing.FontStyle.Regular, System.Drawing.GraphicsUnit.Point, ((System.Byte)(0)));
            this.label1.Location = new System.Drawing.Point(216, 8);
            this.label1.Name = "label1";
            this.label1.Size = new System.Drawing.Size(56, 32);
            this.label1.TabIndex = 14;
            this.label1.Text = "Use Default";
            this.label1.TextAlign = System.Drawing.ContentAlignment.TopRight;
            // 
            // chkKeyFrame
            // 
            this.chkKeyFrame.Location = new System.Drawing.Point(248, 48);
            this.chkKeyFrame.Name = "chkKeyFrame";
            this.chkKeyFrame.Size = new System.Drawing.Size(16, 24);
            this.chkKeyFrame.TabIndex = 15;
            this.chkKeyFrame.CheckedChanged += new System.EventHandler(this.chkKeyFrame_Changed);
            // 
            // chkPFrames
            // 
            this.chkPFrames.Location = new System.Drawing.Point(248, 80);
            this.chkPFrames.Name = "chkPFrames";
            this.chkPFrames.Size = new System.Drawing.Size(16, 24);
            this.chkPFrames.TabIndex = 16;
            this.chkPFrames.CheckStateChanged += new System.EventHandler(this.chkPFrames_Changed);
            // 
            // chkWindowSize
            // 
            this.chkWindowSize.Location = new System.Drawing.Point(248, 112);
            this.chkWindowSize.Name = "chkWindowSize";
            this.chkWindowSize.Size = new System.Drawing.Size(16, 24);
            this.chkWindowSize.TabIndex = 17;
            // 
            // chkQuality
            // 
            this.chkQuality.Location = new System.Drawing.Point(248, 176);
            this.chkQuality.Name = "chkQuality";
            this.chkQuality.Size = new System.Drawing.Size(16, 24);
            this.chkQuality.TabIndex = 18;
            this.chkQuality.CheckedChanged += new System.EventHandler(this.chkQuality_Changed);
            // 
            // CompressionProps
            // 
            this.AcceptButton = this.btnOk;
            this.AutoScaleBaseSize = new System.Drawing.Size(5, 13);
            this.CancelButton = this.btnCancel;
            this.ClientSize = new System.Drawing.Size(274, 276);
            this.ControlBox = false;
            this.Controls.AddRange(new System.Windows.Forms.Control[] {
                                                                          this.chkQuality,
                                                                          this.chkWindowSize,
                                                                          this.chkPFrames,
                                                                          this.chkKeyFrame,
                                                                          this.label1,
                                                                          this.btnCancel,
                                                                          this.btnOk,
                                                                          this.labQuality,
                                                                          this.txtQuality,
                                                                          this.trkQuality,
                                                                          this.labWindowSize,
                                                                          this.labPFrames,
                                                                          this.labKeyFrame,
                                                                          this.txtWindowSize,
                                                                          this.txtPFrames,
                                                                          this.txtKeyFrame});
            this.FormBorderStyle = System.Windows.Forms.FormBorderStyle.FixedDialog;
            this.Name = "CompressionProps";
            this.ShowInTaskbar = false;
            this.Text = "Compression Properties";
            ((System.ComponentModel.ISupportInitialize)(this.trkQuality)).EndInit();
            this.ResumeLayout(false);

        }
		#endregion

        private void Quality_Value_Changed(object sender, System.EventArgs e)
        {
            txtQuality.Text = trkQuality.Value.ToString();
        }

        private void chkKeyFrame_Changed(object sender, System.EventArgs e)
        {
            txtKeyFrame.Enabled = !chkKeyFrame.Checked;
        }

        private void chkPFrames_Changed(object sender, System.EventArgs e)
        {
            txtPFrames.Enabled = !chkPFrames.Checked;
        }

        private void chkQuality_Changed(object sender, System.EventArgs e)
        {
            txtQuality.Enabled = !chkQuality.Checked;
            trkQuality.Enabled = !chkQuality.Checked;
        }

        private void txtKeyFrame_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Validate_Numeric(sender, e);
        }

        private void txtQuality_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Validate_Numeric(sender, e);
        }

        private void txtWindow_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Validate_Numeric(sender, e);
        }

        private void txtPFrames_Validating(object sender, System.ComponentModel.CancelEventArgs e)
        {
            Validate_Numeric(sender, e);
        }

        private void Validate_Numeric(object sender, System.ComponentModel.CancelEventArgs e)
        {
            TextBox t = sender as TextBox;

            try
            {
                Convert.ToInt64(t.Text);
                e.Cancel = false;
            }
            catch
            {
                MessageBox.Show("Illegal value", "Error", MessageBoxButtons.OK, MessageBoxIcon.Error);
                e.Cancel = true;
            }        
        }

        private void btnOK_Click(object sender, System.EventArgs e)
        {
            DialogResult = DialogResult.OK;
        }

    }
}
